package com.example.bookstore.beans;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import com.example.bookstore.details.CustomerDetails;
import com.example.bookstore.details.OrderDetails;
import com.example.bookstore.exception.CustomerNotFoundException;
import com.example.bookstore.exception.InvalidParameterException;

@ManagedBean(name = "customer")
@SessionScoped
public class CustomerBean extends BaseBean {

	private CustomerDetails customer;

	public CustomerBean() {

	}

	public void updateCustomerId() {
		String name = FacesContext.getCurrentInstance().getExternalContext()
				.getUserPrincipal().getName();
		long customerId = Long.parseLong(name);
		try {
			customer = customerController().getDetails(customerId);
		} catch (CustomerNotFoundException e) {
			e.printStackTrace();
		} catch (InvalidParameterException e) {
			e.printStackTrace();
		}

		getSessionMap().put("customer", customer);
	}

	public Long getCustomerId() {
		return customer.getCustomerId();
	}

	public String getName() {
		return "test";
		//return customer.getFirstName() + " " + customer.getLastName();
	}

	public List<OrderDetails> getOrders() {
		return null;
	}

	public OrderDetails getOrderDetails(long orderId) {
		return null;
	}

}
